﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sunt_AjaxWebService.aspx.cs" Inherits="sunt_AJAX_Demo.sunt_AjaxWebServices.sunt_AjaxWebService" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        #div1,#div2,#div3,#div4
        {
            height:15px;
            color:Red;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" AjaxFrameworkMode="Enabled" EnablePageMethods="true">
        <Services>
            <asp:ServiceReference Path="~/sunt_AjaxWebServices/Sunt_WebServecs/sunt_AjaxWebService.asmx" InlineScript="false" />
        </Services>
    </asp:ScriptManager>
    <script type="text/javascript">
        function getRandom() {
            sunt_AJAX_Demo.sunt_AjaxWebServices.Sunt_WebServecs.sunt_AjaxWebService.getRandom(SuccessCallBack);
        }
        function SuccessCallBack(result) {
            $get("div1").innerHTML = result;
        }

        function getRandomByRange(minValue, maxValue) {
            sunt_AJAX_Demo.sunt_AjaxWebServices.Sunt_WebServecs.sunt_AjaxWebService.GetRandomByRange(minValue,maxValue,SuccessCallBack1);
        }
        function SuccessCallBack1(result) {
            $get("div2").innerHTML = result;
        }
        function GetDivision(a, b) {
            sunt_AJAX_Demo.sunt_AjaxWebServices.Sunt_WebServecs.sunt_AjaxWebService.GetDivision(a, b, SuccessCallBack3, FailedCallBack1);
        }
        function SuccessCallBack3(result) {
            $get("div3").innerHTML = result;
        }
        function FailedCallBack1(error) {
            var message = String.format("TimeOut : {0}<br/>Message：{1}<br/>Exception Type : {2}<br/>StackTrace:{3}",
            error.get_timedOut(),
            error.get_message(),
            error.get_exceptionType(),
            error.get_stackTrace()
            );
            $get("div3").innerHTML = message;
        }
        function timeout() {
            alert("timeout");
            sunt_AJAX_Demo.sunt_AjaxWebServices.Sunt_WebServecs.sunt_AjaxWebService.set_timeout = 2;
            sunt_AJAX_Demo.sunt_AjaxWebServices.Sunt_WebServecs.sunt_AjaxWebService.TimeOut(null, FailedCallBack2);
        }
        function FailedCallBack2(error) {
            var message = String.format("TimeOut : {0}<br/>Message：{1}<br/>Exception Type : {2}<br/>StackTrace:{3}",
            error.get_timedOut(),
            error.get_message(),
            error.get_exceptionType(),
            error.get_stackTrace()
            );
            $get("div4").innerHTML = message;
        }
    </script>
    <div>
        <input id="Button1" type="button" value="GetRandom" onclick="getRandom()" />
        <div id="div1"></div>
        <input id="Button2" type="button" value="GetRandomByRange" onclick="getRandomByRange(20,30)" />
        <div id="div2"></div>
        <input id="Button3" type="button" value="GetDivision(20,0)" onclick="GetDivision(20,0)" />
        <div id="div3"></div>
          <input id="Button4" type="button" value="TimeOut" onclick="timeout()" />
        <div id="div4"></div>
    </div>
    </form>
</body>
</html>
